package co.infinum.goldfinger.example.widget;

import co.infinum.goldfinger.example.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

import static ohos.agp.animation.Animator.INFINITE;

/**
 * ex.
 *
 * @author zh
 * @since 2021-06-25
 */
public class ProgressDialog extends CommonDialog {

    /**
     * INFINITE
     */
    public static final int INFINITE = -1;
    private Context context;
    private Image progressBar;

    public ProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_progress, (ComponentContainer) null, true);
        this.setContentCustomComponent(component);
        progressBar = (Image) component.findComponentById(ResourceTable.Id_round_progress_bar);
        setSize(450, 450);
        setTransparent(true);
    }

    @Override
    protected void onShowing() {
        super.onShowing();
        progressBar.createAnimatorProperty()
                .rotate(360).setLoopedCount(INFINITE)
                .setDuration(800).start();
    }
}
